#ifndef CONFIGSEARCHBAR_H
#define CONFIGSEARCHBAR_H

#include <QWidget>
#include <QSet>
#include <QPair>
#include <QLineEdit>
#include "UpdateOption.h"

class ConfigDataModel;
class ConfigItem;
class QLineEdit;
class QMenu;

class ConfigSearchBar : public QLineEdit
{
    Q_OBJECT
public:
    explicit ConfigSearchBar(ConfigDataModel *data, QWidget *parent);
    virtual ~ConfigSearchBar() override;
private:
    ConfigDataModel *m_data;
    QLineEdit *m_searchBar;
    QMenu *m_menu;
    QSet<ConfigItem*> items;
    bool menuContainsText(const QString &text);
    void removeUnusedActions(const QString& usedStr);
    virtual void focusInEvent(QFocusEvent *e) override;
    // virtual void focusOutEvent(QFocusEvent *e) override;
    virtual void mousePressEvent(QMouseEvent *event) override;

private slots:
    void onSearchBarContentChanged(const QString& str);
signals:
};

class ConfigSearchBarWidget : public QWidget
{
    Q_OBJECT
public:
    explicit ConfigSearchBarWidget(ConfigDataModel *data, QWidget *parent = nullptr);
    virtual ~ConfigSearchBarWidget() override;

private:
    ConfigDataModel *m_data;
    QLineEdit *m_searchBar;
    QMenu *m_menu;
    QSet<ConfigItem*> items;
    bool menuContainsText(const QString &text);
    void removeUnusedActions(const QString& usedStr);
    bool eventFilter(QObject *watched, QEvent *event) override;

private slots:
    void onSearchBarContentChanged(const QString& str);
signals:

};

#endif // CONFIGSEARCHBAR_H
